//------------------------------------------------------------------------------
// <copyright file="WebDataService.svc.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Services;
using System.Data.Services.Common;
using System.IO;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using System.Web.Hosting;
using Core.Models;

namespace OData
{
    //[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]  
    public class OData : DataService<BookExchaneContext>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            //config.UseVerboseErrors = true;

            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }

        protected override void HandleException(HandleExceptionArgs e)
        {
            try
            {
                e.UseVerboseErrors = true;
                File.AppendAllText(FullFilePath, e.Exception.ToString());                
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        private string FullFilePath
        {
            get
            {
                string fullFilePath = HostingEnvironment.MapPath("~/log/error.log");
                return fullFilePath;
            }
        }
    }
}
